using UnityEngine;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif

[System.Serializable]
public class UseableInfo : InteractiveInfo
{
	[Header("Useable")]
	public List<StatBonus> bonus = new List<StatBonus>();
	public ActionButton actionButton;
	public enum ActionButton
	{
		Equip,
		Drink,
		Apply,
		Use
	}

	public StatBonus GetStat(StatType _type)
	{
		foreach (StatBonus b in bonus)
		{
			if (b.statType == _type)
			{
				return b;
			}
		}
		
		return null;
	}

	public override string[] GetStrings()
	{
		string[] strings = new string[bonus.Count];
		for (int i = 0; i < bonus.Count; i++)
		{
			strings[i] = bonus[i].GetDisplayString();
		}

		return strings;
	}
	
	public override InteractiveInfo Clone()
	{
		UseableInfo info = base.CloneInteractive<UseableInfo>();
		info.bonus = new List<StatBonus>();
		foreach (StatBonus b in bonus)
		{
			info.bonus.Add(b.Clone());
		}
		
		return info;
	}
	
	#region Editor
	// Return true id it is to be removed
	public override DrawResult DrawEditor()
	{
		DrawResult result = base.DrawEditor();
		if (result != DrawResult.None)
		{
			return result;
		}

		actionButton = (ActionButton)EditorGUILayout.EnumPopup("Action Button", actionButton);

		// Draw bonus items inside two columns
		EditorGUILayout.BeginHorizontal();
		{
			EditorGUILayout.BeginVertical();
			{
				for (int i = 0; i < bonus.Count; i += 2)
				{
					if (bonus[i].Draw())
					{
						bonus.RemoveAt(i);
						break;
					}
				}
			}
			EditorGUILayout.EndVertical();
			EditorGUILayout.BeginVertical();
			{
				for (int i = 1; i < bonus.Count; i += 2)
				{
					if (bonus[i].Draw())
					{
						bonus.RemoveAt(i);
						break;
					}
				}
			}
			EditorGUILayout.EndVertical();
		}
		EditorGUILayout.EndHorizontal();


		if (GUILayout.Button("Add Bonus", GUILayout.Width(100)))
		{
			bonus.Add(new StatBonus());
		}
		
		return DrawResult.None;
	}
	#endregion
}
